package com.njit.mailm.core.controller;

import com.njit.mailm.core.bean.Draft;
import com.njit.mailm.core.service.DraftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * Created by Administrator on 2016/4/21.
 * 包含草稿的保存
 */
@RequestMapping("/mail")
@Controller
public class SaveController {

    @Autowired
    private DraftService draftService;


    @ResponseBody
    @RequestMapping(value = "saveDraft",method = RequestMethod.POST)
    public void saveDraft(Draft draft){
//        System.out.println(draft.toString());
        draft.setSaveTime(new Date());
        if(draftService.getDraftById(draft.getId()) != null){
            draftService.updateDraft(draft);
        }else{
            if(draft.getId() != null){
                draftService.insertDraft(draft);
            }
        }
    }

}
